#include "ParticleExplosiveLight.h"

#include "ParticleContext.h"
#include "ParticleSimple.h"
#include "DescriptorParticle.h"

using namespace ParticleEngine; 

const DescriptorParticle ParticleExplosiveLight::Descriptor
(
	"ExplosiveLight", 
	[](ParticleContext& NewContext) { return new ParticleExplosiveLight(NewContext); }
); 

ParticleExplosiveLight::ParticleExplosiveLight(ParticleContext& NewContext) :
ParticleBase(NewContext, &ParticleExplosiveLight::Descriptor),
Heat(0.3f)
{
	Adhesions = new PropertyAdhesions(0.03f);
	Adhesions->ParticleCast = this;
}
ParticleExplosiveLight::~ParticleExplosiveLight()
{
}

void ParticleExplosiveLight::Sole()//einzelne aktualisierzung
{
	this->SoleStandard();
	if (Heat.ContentAdjust > 0.001f)
	{
		this->Context.ToRemoveArray.Add(this);
		ParticleBase* NewParticle = new ParticleSimple(this->Context);
		NewParticle->Pos = this->Pos;
		NewParticle->Velocity = this->Velocity;
		this->Context.ToAddArray.Add(NewParticle);
		return;
	}

	this->Heat.Sole();

	if (this->Heat.Volume > 0.8)
	{
		this->Context.ToRemoveArray.Add(this);
		ParticleBase* NewParticle = new ParticleSimple(this->Context);
		NewParticle->Pos = this->Pos;
		NewParticle->Velocity = this->Velocity;
		this->Context.ToAddArray.Add(NewParticle);
	}
}
void ParticleExplosiveLight::InteractionIndividual(ParticleBase*const Other, Vec<2, float>& Space, const float& DistanceSquared)
{
	this->InteractionKinetics(Other, Space, DistanceSquared);

	this->Heat.Interaction(Other->HasHeat());
}
ColorRGBA<unsigned char> ParticleExplosiveLight::GetColor()
{
	return ColorRGBA<unsigned char> (200, 0, 200, 255);
}

void ParticleExplosiveLight::SaveIndividual(std::ofstream& Strm)
{
	Heat.Save(Strm);
}
void ParticleExplosiveLight::LoadIndividual(std::ifstream& Strm)
{
	Heat.Load(Strm);
}


